package com.zzedu.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zzedu.common.annotation.Log;
import com.zzedu.common.core.controller.BaseController;
import com.zzedu.common.core.domain.AjaxResult;
import com.zzedu.common.core.page.TableDataInfo;
import com.zzedu.common.enums.BusinessType;
import com.zzedu.common.utils.ServletUtils;
import com.zzedu.common.utils.poi.ExcelUtil;
import com.zzedu.domain.ZzChargeOrderPay;
import com.zzedu.dto.ZzChargeOrderPayDTO;
import com.zzedu.service.IZzChargeOrderPayService;
import com.zzedu.vo.ZzChargeOrderPayVO;
import com.zzedu.vo.ZzChargeOrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * (教育-学校)收费订单_付款Controller
 *
 * @author Mr.Wang
 * @date 2025-10-18
 */
@RestController
@RequestMapping("/report/pay")
public class ZzChargeOrderPayController extends BaseController {
    @Autowired
    private IZzChargeOrderPayService zzChargeOrderPayService;

    /**
     * 查询(教育-学校)收费订单_付款列表
     */
    @PreAuthorize("@permission.hasAnyPermissions('report:pay:query')")
    @RequestMapping("/list")
    public TableDataInfo list(@RequestBody ZzChargeOrderPayDTO zzChargeOrderPay) {
        IPage<ZzChargeOrderPay> page = zzChargeOrderPayService.page(zzChargeOrderPay.getPageDTO(), zzChargeOrderPayService.buildQuery(zzChargeOrderPay));

        return getDataTable(page,zzChargeOrderPayService.convertVO(page.getRecords()));
    }

    /**
     * 导出(教育-学校)收费订单_付款列表
     */
    @PreAuthorize("@permission.hasAnyPermissions('report:pay:export')")
    @Log(title = "(教育-学校)收费订单_付款", businessType = BusinessType.EXPORT)
    @RequestMapping("/export")
    public void export(ZzChargeOrderPayDTO zzChargeOrderPay) {
        zzChargeOrderPay.setPageNum(-1L);
        zzChargeOrderPay.setPageSize(-1L);
        IPage<ZzChargeOrderPay> page = zzChargeOrderPayService.page(zzChargeOrderPay.getPageDTO(), zzChargeOrderPayService.buildQuery(zzChargeOrderPay));
        ExcelUtil<ZzChargeOrderPayVO> util = new ExcelUtil<ZzChargeOrderPayVO>(ZzChargeOrderPayVO.class);
        util.exportExcel(ServletUtils.getResponse(), zzChargeOrderPayService.convertVO(page.getRecords()), "收费订单数据");
    }


    /**
     * 新增保存(教育-学校)收费订单_付款
     */
    @PreAuthorize("@permission.hasAnyPermissions('report:pay:add')")
    @Log(title = "(教育-学校)收费订单_付款", businessType = BusinessType.INSERT)
    @RequestMapping("/add")
    public AjaxResult addSave(@Validated @RequestBody ZzChargeOrderPay zzChargeOrderPay) {
        return toAjax(zzChargeOrderPayService.save(zzChargeOrderPay));
    }


    /**
     * 获取(教育-学校)收费订单_付款详细信息
     */
    @PreAuthorize("@permission.hasAnyPermissions('report:pay:query')")
    @RequestMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(zzChargeOrderPayService.getById(id));
    }


    /**
     * 修改保存(教育-学校)收费订单_付款
     */
    @PreAuthorize("@permission.hasAnyPermissions('report:pay:edit')")
    @Log(title = "(教育-学校)收费订单_付款", businessType = BusinessType.UPDATE)
    @RequestMapping("/edit")
    public AjaxResult editSave(@Validated @RequestBody ZzChargeOrderPay zzChargeOrderPay) {
        return toAjax(zzChargeOrderPayService.updateById(zzChargeOrderPay));
    }

    /**
     * 删除(教育-学校)收费订单_付款
     */
    @PreAuthorize("@permission.hasAnyPermissions('report:pay:remove')")
    @Log(title = "(教育-学校)收费订单_付款", businessType = BusinessType.DELETE)
    @RequestMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(zzChargeOrderPayService.removeBatchByIds(ids));
    }


    @PreAuthorize("@permission.hasAnyPermissions('report:pay:import')")
    @Log(title = "用户管理", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
        ExcelUtil<ZzChargeOrderVO> util = new ExcelUtil<ZzChargeOrderVO>(ZzChargeOrderVO.class);
        List<ZzChargeOrderVO> zzChargeOrderPayVOS = util.importExcel(file.getInputStream());
        String message = zzChargeOrderPayService.importData(zzChargeOrderPayVOS,updateSupport);
        return AjaxResult.success(message);
    }
    /**
     * 确认收款
     */
    @PreAuthorize("@permission.hasAnyPermissions('report:pay:confirm')")
    @Log(title = "收费订单", businessType = BusinessType.UPDATE)
    @RequestMapping("/confirm/{ids}")
    public AjaxResult confirm(@PathVariable List<Long> ids) {
        return toAjax(zzChargeOrderPayService.confirm(ids));
    }
}
